#include <reg51.h>

typedef unsigned char uint8;
typedef unsigned int  uint16;

sbit down = P3^0;
sbit up = P3^1;

uint8 t = 0;
uint8 PWM_T = 0;  

void delay(uint16 t)
{
    uint16 x,y;
    for(x=t;x>0;x--)
        for(y=120;y>0;y--);
}

void main(void)      
{

    TMOD = 0x02; 
    TH0=210;     
    TL0=210;     
    TR0=1;       
    ET0=1;       
    EA=1;     
    P1=0xff;      
    PWM_T=30;
     while(1)     
     {   
           if(!up)
             {
                if(PWM_T<250)
                    {
                      PWM_T++;
                    }            
                delay(10);
            }
         if(!down)
             {
                if(PWM_T>0)
                    {
                      PWM_T--;
                    }
                
                delay(10);
            }

    
     }      
}
timer0() interrupt 1  
{ 
     t++;    
     if(t==250)   
         {
              t=0;  
              P1=0x00;
         }
     if(PWM_T==t) 
         {  
             P1=0xff;    
         }
}